/* jshint esversion: 8 */
import * as types from '@/store/types.js';
import { getCartList } from '@/api/ShoppingCart';

export default {
  state: {
    ShoppingCart: {},
  },
  
  getters: {
    /*** 返回 获取购物车的数据 数据 ***/
    [types.GShoppingCart](state) {
      return state.ShoppingCart;
    },
  },

  actions: {
    /*** 获取 获取购物车的数据 数据 ***/
    [types.AShoppingCart](ctx, query) {
      return new Promise((resolve, reject) => {
        getCartList(query).then(({data}) => {
          ctx.commit(types.MShoppingCart, data);
          resolve();
        }).catch(error => {
          ctx.commit(types.MShoppingCart, {});
          reject(error);
        });
      });
    },
  },

  mutations: {
    /*** 填充 获取购物车的数据 数据 ***/
    [types.MShoppingCart](state, access) {
      state.ShoppingCart = access;
    },
  }
};